import axios from "axios";
// 设置基本配置
axios.defaults.baseURL = "/";
axios.defaults.timeout = 10000;

axios.interceptors.response.use(
  (response) => {
    // 对响应数据做点什么
    console.log(response, "---response--");

    return response.data;
  },
  (error) => {
    // 对响应错误做点什么
    return Promise.reject(error);
  }
);

//封装对应的get请求
const get = (url, params) => {
  return new Promise((resolve, reject) => {
    axios
      .get(url, { params })
      .then((res) => resolve(res))
      .catch((err) => reject(err));
  });
};

//封装对应的post请求
export const post = (url, param) => {
  return new Promise((resolve, reject) => {
    axios
      .post(url, param)
      .then((res) => resolve(res))
      .catch((err) => reject(err));
  });
};
